package com.atguigu.distributed.lock.leecode.greedy;

/**
 * 力扣中等55跳跃游戏
 */
public class JumpGame {
    public static void main(String[] args) {
        int[] nums = {2,3,1,1,4};
        JumpGame test = new JumpGame();
        boolean b = test.canJump(nums);
        System.out.println("res==>"+b);
    }
    public boolean canJump(int[] nums) {
        int end = 0;
        int maxPosition = 0;
        int step = 0;
        boolean result = false;
        for (int i = 0; i < nums.length; i++) {
            maxPosition = Math.max(maxPosition, i + nums[i]);
            if(i==end){
                end = maxPosition;
                step++;
            }
            if(i==nums.length-1){
                if(i>end){
                    result = false;
                }else {
                    result = true;
                }
            }

        }
        return result;
    }
}
